﻿using OA.Core;
using OA.Core.Helper;
using OA.Model.MyAttribute;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OA.Model
{

    public enum ApprovalTreeType
    {
        [Description("审批流程")]
        Approval =1,

        [Description("处理流程")]
        Conduct =2
    }
    /// <summary>
    /// 审批树
    /// </summary>
    public class ApprovalTree : BaseInfo
    {
        [Display(Name = "流程树名称")]
        [MaxLength(20)]
        [Tag(TagEnum.Text, "required", "流程树名称", 3, 20)]
        public string Name { get; set; }      

        [Display(Name = "所属单据")]
        [Tag(TagEnum.Select, "required", "所属单据",null)]
        public int CustomFormID { get; set; }
    }

    public class SimpleApprovalTree : SimpleInfo
    {
        public int CustomFormID { get; set; }

        public string Name { get; set; }

        /// <summary>
        /// 所属单据
        /// </summary>
        public string CustomFormName { get; set; }

        
        public static Expression<Func<ApprovalTree, SimpleApprovalTree>> Map = m => new SimpleApprovalTree()
        {
            ID = m.ID,
            Name = m.Name,
            CustomFormID=m.CustomFormID
        };

    }

    public enum ApprovalNodeType
    {
        [Description("普通节点")]
        Normal = 1,
        [Description("会签节点")]
        Countersign = 2,        
        [Description("组织上的上级")]
        BaseDepartment = 3,
    }

    /// <summary>
    /// 审批节点  起草节点每个岗位只能有一个，审批节点可以有几个
    /// </summary>
    public class ApprovalNode : BaseInfo
    {
        public int Status { get; set; }

        public int NodeID { get; set; }

        public string NodeName { get; set; }

        public int ParentNodeID { get; set; }

        /// <summary>
        /// 1:普通节点  2:会签节点  3 组织上的上级
        /// </summary>
        [Display(Name = "节点类型")]
        [Tag(TagEnum.Select,typeof(ApprovalNodeType), "节点类型", true)]
        public int TypeID { get; set; } = 1;

        /// <summary>
        /// 是否起草节点
        /// </summary>
        [Display(Name = "起草节点")]
        [Tag(TagEnum.Switch, "","","")]
        public bool IsDraftsNode { get; set; }


        // [Index("CustomFormID")]
        public int CustomFormID { get; set; }

        /// <summary>
        /// 所属部门 
        /// </summary>
        [Display(Name = "所属部门")]
        public int DepartmentID { get; set; } 


        [Required]
        [Display(Name = "节点名称")]
        [Tag(TagEnum.Text, "required", "节点名称", 3, 20)]
        [MaxLength(50)]
        public string Name { get; set; }        
         
        /// <summary>
        /// 岗位ID
        /// </summary>
        [Display(Name = "岗位ID")]
        [Tag(TagEnum.Select, "required", "节点名称", "0")]
        public int PositionID { get; set; }


        /// <summary>
        /// 可编辑字段
        /// </summary>
        [Tag(TagEnum.Hidden, "required", "可编辑字段", "")]
        public string EnableEditableFields { get; set; }


        /// <summary>
        /// 隐私字段
        /// </summary>
        [Tag(TagEnum.Hidden, "required", "隐私字段", "")]
        public string PrivacyFields { get; set; }

        /// <summary>
        /// 过滤条件 List<Condition> Json 串
        /// </summary>
        public string Conditions { get; set; }


        [MaxLength(200)]
        [Display(Name = "会签岗位")]
        [Tag(TagEnum.Text, "required", "会签岗位", "")]
        public string Countersign { get; set; }

        [NotMapped]
        public List<int> Countersigns { get { return JsonHelper.DeserializeList<int>(this.Countersign); } }



        [NotMapped]
        public string EmpID { get; set; }

        [NotMapped]
        public string EmpName { get; set; }

        [NotMapped]
        public int Step { get; set; }

        /// <summary>
        /// 前置审批节点
        /// </summary>
        public bool IsPre { get; set; }



        [NotMapped]
        public List<Condition> ListCondition { get; set; }

    }



    public enum ProcessPointType
    {
        [Description("员工工号")]
        One = 1,

        [Description("岗位节点")]
        Two = 2

    }
    
    public class ProcessPoint : BaseInfo
    {
       // [Index("CustomFormID")]
        public int CustomFormID { get; set; }        

        [Display(Name = "所属部门")]
        public int DepartmentID { get; set; }

        /// <summary>
        /// 上级节点
        /// </summary>
        public int ParentID { get; set; }

        [Required]
        [Display(Name = "节点名称")]
        [Tag(TagEnum.Text, "required", "节点名称", 3, 20)]
        [MaxLength(50)]
        public string Name { get; set; }

        /// <summary>
        /// 工号
        /// </summary>
        [Display(Name = "员工工号")]
        [Tag(TagEnum.Select, "required", "节点名称", "请选择")]
        [MaxLength(10)]
        [Required]
        public string EmpID { get; set; }

        /// <summary>
        /// 岗位ID
        /// </summary>
        [Display(Name = "岗位ID")]
        [Tag(TagEnum.Select, "required", "节点名称", "0")]
        public int PositionID { get; set; }

        /// <summary>
        /// 可编辑字段
        /// </summary>
        [Tag(TagEnum.Hidden, "required", "可编辑字段", "")]
        public string EnableEditableFields { get; set; }

        /// <summary>
        /// 过滤条件 List<Condition> Json 串
        /// </summary>
        public string Conditions { get; set; }

        [NotMapped]
        public List<Condition> ListCondition { get; set; }

    }

    public enum ConditionType
    {
        [Description("等于 Value")]
        One = 1,
        [Description("大于等于Value")]
        Two = 2,
        [Description("包含在Value中")]
        Three = 3,
       
    }

    public class Condition
    {   
        /// <summary>
        /// 分组ID
        /// </summary>
        public int GroupID { get; set; }

        /// <summary>
        /// 1:等于Value 2:大于等于Value 3:存在于Value中
        /// </summary>
        [Tag(TagEnum.Select2,typeof(ConditionType),"",true)]
        public int TypeID { get; set; }

        [Tag(TagEnum.Select, null, "", true)]
        public string KeyWord { get; set; }

        public string Value { get; set; }

    }

}
